package com.example.spring.exercise.repository;

import com.example.spring.exercise.service.dto.rouge.RougeInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

/**
 * @author : zhayh
 * @Date : 2021-4-4 11:16
 * @Description:
 */

@Repository
public interface RougeRepository extends JpaRepository<RougeInfo, Long> {
    // JPQL 语句查询
    @Query("select a from RougeInfo a where a.rougeBrand.brandCountry = ?1 " +
            "and a.rougePrice >= ?2 and a.rougePrice <= ?3 ")
    Page<RougeInfo> selectByCountry(String country, Float minPrice, Float maxPrice, Pageable pageable);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update RougeInfo set rougeName=?2 where id=?1")
    int updateRougeName(Long id, String rougeName);
}
